package org.rectask.admin;

import java.io.*;
import java.util.*;

import org.rectask.model.*;
import org.rectask.model.Date;

public class FileManager {
    /**
     * 
     * @param taskList
     */
    public static void xmlSave(ArrayList<Task> taskList, String filename) {
	String result = new String();
	result += getXmlHeader();
	for (Iterator<Task> itr = taskList.iterator(); itr.hasNext();) {
	    Task nextTask = itr.next(); 
	    result += nextTask.toXML();
	}
	File file = new File(filename);
	FileWriter out;
	try {
	    out = new FileWriter(file);
	    out.write(result);
	    out.close();
	} catch (IOException e) {
	    System.out.println("Error writing to file.");
	}
    }

    private static String getXmlHeader() {
	//TODO
	return "<xml etc etc/>";
    }
    
    public static void main(String args[]) {
	Task task1 = new Task("New task", new Date(1, 1, 2009), 3, 6);
	task1.addExecutionDate(new Date(3,1,2009));
	task1.addExecutionDate(new Date(6,1,2009));
	task1.addExecutionDate(new Date(13,1,2009));
	Task task2 = new Task("New task", new Date(1, 1, 2009), 2, 5);
	task2.addExecutionDate(new Date(3,1,2009));
	task2.addExecutionDate(new Date(13,1,2009));
	task2.addExecutionDate(new Date(3,12,2008));
	ArrayList<Task> taskList = new ArrayList<Task>();
	taskList.add(task1);
	taskList.add(task2);
	FileManager.xmlSave(taskList, "file1.xml");
    }
}
